<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cusName">
              <a-input v-model="model.cusName" placeholder="请输入户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="户号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cusId">
              <j-dict-select-tag type="list" v-model="model.cusId" dictCode="mws_t_arc_customers,code,id" placeholder="请选择户号" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="缴费类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeTargetType">
              <a-input v-model="model.feeTargetType" placeholder="请输入缴费类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="money">
              <a-input-number v-model="model.money" placeholder="请输入金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="预存操作时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chargeTime">
              <a-input v-model="model.chargeTime" placeholder="请输入预存操作时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="收费员" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cashierId">
              <a-input v-model="model.cashierId" placeholder="请输入收费员"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="账务月份" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="financialMonth">
              <a-input v-model="model.financialMonth" placeholder="请输入账务月份"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="冲账状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="feeStruckStatus">
              <a-input v-model="model.feeStruckStatus" placeholder="请输入冲账状态"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="有效状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入有效状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="预存前账户余额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preMoney">
              <a-input-number v-model="model.preMoney" placeholder="请输入预存前账户余额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="预存后账户余额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="postMoney">
              <a-input-number v-model="model.postMoney" placeholder="请输入预存后账户余额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否打印" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isPrint">
              <a-input-number v-model="model.isPrint" placeholder="请输入是否打印" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="是否删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="delFlag">
              <a-input-number v-model="model.delFlag" placeholder="请输入是否删除" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChgStoredsForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           cusId: [
              { required: true, message: '请输入户号!'},
           ],
           feeTargetType: [
              { required: true, message: '请输入缴费类型!'},
           ],
           money: [
              { required: true, message: '请输入金额!'},
           ],
           chargeTime: [
              { required: true, message: '请输入预存操作时间!'},
           ],
           cashierId: [
              { required: true, message: '请输入收费员!'},
           ],
           financialMonth: [
              { required: true, message: '请输入账务月份!'},
           ],
           feeStruckStatus: [
              { required: true, message: '请输入冲账状态!'},
           ],
           status: [
              { required: true, message: '请输入有效状态!'},
           ],
        },
        url: {
          add: "/chg/chgStoreds/add",
          edit: "/chg/chgStoreds/edit",
          queryById: "/chg/chgStoreds/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>